package study.day4.t3;

public class BookManager {
    //定义一个数组来管理书本
    Book[] books=new Book[6];
    //初始化书本
    public void initBooks(){
    Book book=new Book();
    book.name="活着";
    book.author="余华";
    book.price=47;
    books[0]=book;
    Book book2=new Book();
    book2.name="平凡的世界";
    book2.author="路遥";
    book2.price=50;
    books[1]=book2;
    }
    //图书列表
    public void bookList(){
        System.out.println("这是一个图书系统");
        System.out.println("图书名字\t\t作者\t\t价格\t\t");
        for (Book book : books) {
            if (book != null) {
                System.out.println(book.name + "\t\t" + book.author + "\t\t" + book.price);
            }
        }
    }
    //添加图书
    public boolean addBook(Book book){
        boolean flag=false;
        for(int i=0; i<books.length; i++){
            if(books[i]==null){
                books[i]=book;
                flag=true;
                break;
            }
        }
        return flag;
    }
}
